﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DO.Clustering;

namespace BLL.Clustering
{
    public class ClusterLabelManager
    {
        public static string GetClusterLabel(
            List<int> includedDocIDs,
            Dictionary<int,Dictionary<int, int>> docTermFreqs,
            Dictionary<int,string> terms)
        {
            Dictionary<int, Dictionary<int, int>> includedDocTermFreqs = new Dictionary<int, Dictionary<int, int>>();
            foreach(int docID in includedDocIDs)
            {
                Dictionary<int, int> termFreqs = docTermFreqs[docID];
                includedDocTermFreqs.Add(docID, termFreqs);
            }
            Dictionary<int,double> termWeights =
                TermWeightManager.GetTfidfScores(includedDocTermFreqs, terms);
            List<Feature> feats=new List<Feature>();
            foreach(int termID in terms.Keys)
            {
                Feature feat=new Feature();
                feat.FeatureID = termID;
                feat.Name = terms[termID];
                feat.Weight = termWeights[termID];
                feats.Add(feat);
            }
            feats.Sort();
            StringBuilder buffer=new StringBuilder();
            int termCount = 0;
            foreach(Feature feat in feats)
            {
                if (buffer.Length > 0)
                    buffer.Append(" ");
                buffer.Append(feat.Name);
                termCount++;
                if(termCount>5)
                    break;
            }
            return buffer.ToString();
        }
    }
}
